<?php
/**
 * 缓存对象设置类
 * it's static
 */
class Cache{
	protected static  $cache_type;
	public static  $object;
	private static  $cache_class;
	
	/**
	 * Get cache instance object
	 *
	 * @param string cache type (file,apc,memcache,memory) default:file
	 * @return object cache
	 */
	public static function instance($cache_type='file'){
		if(null!=$cache_type){
			self::$cache_type = $cache_type;
		}
		self::$cache_class = ucfirst('cache_'). ucfirst(self::$cache_type);
		if(self::$object[self::$cache_type]===NULL){
			Mid::loadClass('cache/'. self::$cache_type);
			if($cache_type==='file'){
				self::$object[self::$cache_type] = new self::$cache_class(array('cache_dir' ,Config::Get('cache_dir')));
			}else{
				self::$object[self::$cache_type] = new self::$cache_class;
			}
		}
		return self::$object[self::$cache_type];
	}
}
?>